<?php

if(!function_exists('dddd')){
    function dddd(){
        echo 'dumppppp...';
    }
}

if(!function_exists('get_user_avatar')){
    function get_user_avatar(string $avatar=null)
    {
        return config('url').($avatar??'/images/avatar/default.png');
    }
}

/*获取所有目录*/
if(!function_exists('get_categoires_all')){
    function get_categoires_all($category_id=0)
    {
        //todo:缓存取

        $categories = \App\Models\Category::select('id','name')->get();
        //判断当前所在目录，用于前端active样式
        if($category_id){
            $categories->map(function ($cate) use ($category_id){
                if($cate->id==$category_id){
                    $cate->current_page_active = true;
                }
            });
        }

        return $categories;
    }
}
/*
 * seo处理，默认截取前200个字段
 * */
if(!function_exists('content_seo')){
    function content_seo(string $content,$length = 200)
    {
        //过滤换行、回车，成为空格
        $desc = trim(preg_replace('/\r\n|\r|\n+/',' ',strip_tags($content)));

        return str()->limit($desc,$length);
    }
}
